﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Mimoza.GUI;

namespace Mimoza.CitrixPlugin
{
    public partial class LocalResourcesPage : Mimoza.GUI.WizardPage
    {
        private CitrixData m_data;

        public LocalResourcesPage()
        {
            InitializeComponent();
        }

        override public void Init()
        {
            m_data = this.Wizard.UserData as CitrixData;

            comboBoxKeyboard.SelectedIndex = (int)m_data.Keyboard;

            checkBoxSound.Checked = m_data.Sound.IsSoundEnabled;
            comboBoxSoundQuality.SelectedIndex = (int)m_data.Sound.SoundQuality;
            comboBoxMic.SelectedIndex = (int)m_data.Sound.Microphone;

            checkBoxSound_CheckedChanged(null, null);

            this.comboBoxMic.SelectedIndexChanged += new System.EventHandler(this.comboBoxMic_SelectedIndexChanged);
            this.comboBoxSoundQuality.SelectedIndexChanged += new System.EventHandler(this.comboBoxSoundQuality_SelectedIndexChanged);
            this.checkBoxSound.CheckedChanged += new System.EventHandler(this.checkBoxSound_CheckedChanged);
        }

        override public bool Try2LeavePage(WizardPageLeavingDirection direction)
        {
            if (direction == WizardPageLeavingDirection.Back)
            {
                return true;
            }

            m_data.Keyboard = (Keyboard)comboBoxKeyboard.SelectedIndex;

            m_data.Sound.IsSoundEnabled = checkBoxSound.Checked;
            m_data.Sound.SoundQuality = (SoundQuality)comboBoxSoundQuality.SelectedIndex;
            m_data.Sound.Microphone = (Microphone)comboBoxMic.SelectedIndex;
        
            return true;
        }
        
        private void checkBoxSound_CheckedChanged(object sender, EventArgs e)
        {
            labelQuality.Enabled = checkBoxSound.Checked;
            comboBoxSoundQuality.Enabled = checkBoxSound.Checked;

            labelMic.Enabled = checkBoxSound.Checked;
            comboBoxMic.Enabled = checkBoxSound.Checked;

            if (null != sender)
            {
                this.RaiseOnPageModified();
            }
        }

        private void comboBoxSoundQuality_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.RaiseOnPageModified();
        }

        private void comboBoxMic_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.RaiseOnPageModified();
        }

        private void comboBoxKeyboard_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.RaiseOnPageModified();
        }
    }
}
